package offer;

/**
 * <p>
 * 剑指 Offer 04. 二维数组中的查找
 * </p>
 *
 * @author xiaoboom
 * @date 2021/9/24 23:21
 */
public class Offer04 {
    public static void main(String[] args) {
        int[][] matrix = {
                {1, 4, 7, 11, 15},
                {2, 5, 8, 12, 19},
                {3, 6, 9, 16, 22},
                {10, 13, 14, 17, 24},
                {18, 21, 23, 26, 30}
        };

        System.out.println(findNumberIn2DArray(matrix, 5));
    }

    public static boolean findNumberIn2DArray(int[][] matrix, int target) {
        for (int[] ints : matrix) {
            for (int anInt : ints) {
                if (target == anInt) {
                    return true;
                }
            }
        }
        return false;
    }
}
